package org.performancetracker.jdbc4;

import java.sql.*;
import java.util.Map;

/**
 * @author: jaronschut
 */

public abstract class AbstractMonitoringConnection implements Connection {

    abstract protected Connection getRealConnection();

    public Statement createStatement() throws SQLException {
        return new MonitoringStatement(getRealConnection().createStatement(), getRealConnection());
    }

    public PreparedStatement prepareStatement(String sql) throws SQLException {
        return new PreparedMonitoringStatement(getRealConnection().prepareStatement(sql), getRealConnection());
    }

    public CallableStatement prepareCall(String sql) throws SQLException {
        return new CallableMonitoringStatement(getRealConnection().prepareCall(sql), getRealConnection());
    }

    public String nativeSQL(String sql) throws SQLException {
        return getRealConnection().nativeSQL(sql);
    }

    public void setAutoCommit(boolean autoCommit) throws SQLException {
        getRealConnection().setAutoCommit(autoCommit);
    }

    public boolean getAutoCommit() throws SQLException {
        return getRealConnection().getAutoCommit();
    }

    public void commit() throws SQLException {
        getRealConnection().commit();
    }

    public void rollback() throws SQLException {
        getRealConnection().rollback();
    }

    public void close() throws SQLException {
        getRealConnection().close();
    }

    public boolean isClosed() throws SQLException {
        return getRealConnection().isClosed();
    }

    public DatabaseMetaData getMetaData() throws SQLException {
        return getRealConnection().getMetaData();
    }

    public void setReadOnly(boolean readOnly) throws SQLException {
        getRealConnection().setReadOnly(readOnly);
    }

    public boolean isReadOnly() throws SQLException {
        return getRealConnection().isReadOnly();
    }

    public void setCatalog(String catalog) throws SQLException {
        getRealConnection().setCatalog(catalog);
    }

    public String getCatalog() throws SQLException {
        return getRealConnection().getCatalog();
    }

    public void setTransactionIsolation(int level) throws SQLException {
        getRealConnection().setTransactionIsolation(level);
    }

    public int getTransactionIsolation() throws SQLException {
        return getRealConnection().getTransactionIsolation();
    }

    public SQLWarning getWarnings() throws SQLException {
        return getRealConnection().getWarnings();
    }

    public void clearWarnings() throws SQLException {
        getRealConnection().clearWarnings();
    }

    public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
        return new MonitoringStatement(getRealConnection().createStatement(resultSetType, resultSetConcurrency), getRealConnection());
    }

    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
        return new PreparedMonitoringStatement(getRealConnection().prepareStatement(sql, resultSetType, resultSetConcurrency), getRealConnection());
    }

    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
        return new CallableMonitoringStatement(getRealConnection().prepareCall(sql, resultSetType, resultSetConcurrency), getRealConnection());
    }

    public Map<String, Class<?>> getTypeMap() throws SQLException {
        return getRealConnection().getTypeMap();
    }

    public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
        getRealConnection().setTypeMap(map);
    }

    public void setHoldability(int holdability) throws SQLException {
        getRealConnection().setHoldability(holdability);
    }

    public int getHoldability() throws SQLException {
        return getRealConnection().getHoldability();
    }

    public Savepoint setSavepoint() throws SQLException {
        return getRealConnection().setSavepoint();
    }

    public Savepoint setSavepoint(String name) throws SQLException {
        return getRealConnection().setSavepoint(name);
    }

    public void rollback(Savepoint savepoint) throws SQLException {
        getRealConnection().rollback(savepoint);
    }

    public void releaseSavepoint(Savepoint savepoint) throws SQLException {
        getRealConnection().releaseSavepoint(savepoint);
    }

    public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
        return new MonitoringStatement(getRealConnection().createStatement(resultSetType, resultSetConcurrency, resultSetHoldability), getRealConnection());
    }

    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
        return new PreparedMonitoringStatement(getRealConnection().prepareStatement(sql, resultSetType, resultSetConcurrency), getRealConnection());
    }

    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
        return new CallableMonitoringStatement(getRealConnection().prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability), getRealConnection());
    }

    public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
        return new PreparedMonitoringStatement(prepareStatement(sql, autoGeneratedKeys), getRealConnection());
    }

    public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
        return new PreparedMonitoringStatement(prepareStatement(sql, columnIndexes), getRealConnection());
    }

    public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
        return new PreparedMonitoringStatement(prepareStatement(sql, columnNames), getRealConnection());
    }
    
}
